package com.yike.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yike.common.base.BaseServiceImpl;
import com.yike.common.pagination.Paging;
import com.yike.common.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yike.order.entity.OrderDetail;
import com.yike.order.mapper.OrderDetailMapper;
import com.yike.order.param.OrderDetailPageParam;
import com.yike.order.service.OrderDetailService;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 订单详情表 服务实现类
 *
 * @author yike
 * @since 2024-07-17
 */
@Slf4j
@Service
public class OrderDetailServiceImpl extends BaseServiceImpl<OrderDetailMapper, OrderDetail> implements OrderDetailService {

    @Autowired
    private OrderDetailMapper orderDetailMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveOrderDetail(OrderDetail orderDetail) throws Exception {
        return super.save(orderDetail);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateOrderDetail(OrderDetail orderDetail) throws Exception {
        return super.updateById(orderDetail);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteOrderDetail(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<OrderDetail> getOrderDetailPageList(OrderDetailPageParam orderDetailPageParam) throws Exception {
        Page<OrderDetail> page = new PageInfo<>(orderDetailPageParam, OrderItem.desc(getLambdaColumn(OrderDetail::getCreateTime)));
        LambdaQueryWrapper<OrderDetail> wrapper = new LambdaQueryWrapper<>();
        IPage<OrderDetail> iPage = orderDetailMapper.selectPage(page, wrapper);
        return new Paging<OrderDetail>(iPage);
    }

}
